package engine.scene
{
	import flash.display.MovieClip;
	import flash.display.Shape;
	
	import newx.StageInfo;
	import newx.com.ResManager;

	/**
	 *	场景边框 
	 * @author lw
	 * 
	 */
	public class SceneFrameLogic
	{
		private var _topFrame 		: MovieClip;
		
		private var _downFrame 	: MovieClip;
		
		private var _mask			: Shape;
		
		private var _show			: Boolean;
		
		private static var	_self	:SceneFrameLogic;
		
		public static function getInstance():SceneFrameLogic
		{
			if ( _self == null )
			{
				_self = new SceneFrameLogic();
			}
			return _self;
		}
		
		public function SceneFrameLogic()
		{
			_topFrame = ResManager.newResClass( "shang" ) as MovieClip;
			_downFrame = ResManager.newResClass( "xia" ) as MovieClip;
			
			StageInfo.effectSpace.addChild( _topFrame );
			StageInfo.effectSpace.addChild( _downFrame );
		
			_mask = new Shape();
			_mask.graphics.beginFill(0xFF8800,.5);
			_mask.graphics.drawRect(0,0,1800,768);
			_mask.graphics.endFill();
			StageInfo.stage.addChild(_mask);
			_mask.visible = false;
			
			onChangeSize();
		}
		
		public function onChangeSize():void
		{
			_topFrame.x = _downFrame.x = SceneChangeManager.getGameMinWidhtOffsize();
			_topFrame.y = SceneChangeManager.getGameY() - 15;
			_downFrame.y = 568;
			
			var stageWidth : int = StageInfo.stage.stageWidth;
			var stageHeight : int = StageInfo.stage.stageHeight;
			
			if( stageWidth <= StageInfo.rootMaxW && stageHeight <= StageInfo.rootMaxH )
			{
				StageInfo.mainSpace.mask = null;
				return;
			}
			
			if( stageWidth > StageInfo.rootMaxW )
			{
				_mask.x = ( stageWidth - StageInfo.rootMaxW ) * .5;
			}else
			{
				_mask.x = 0;
			}
			if( stageHeight > StageInfo.rootMaxH )
			{
				_mask.y = ( stageHeight - StageInfo.rootMaxH ) * .5;
			}else
			{
				_mask.y = 0;
			}
			_mask.width = StageInfo.rootMaxW;
			_mask.height = StageInfo.rootMaxH;
			StageInfo.mainSpace.mask = _mask;
		}

		public function get show():Boolean
		{
			return _show;
		}

		public function set show(value:Boolean):void
		{
			_show = value;
			
			_downFrame.visible = _topFrame.visible = _show;
		}
	}
}